package cn.dankal.flyaudio.adapter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.jeremyliao.liveeventbus.LiveEventBus;

import cn.dankal.basiclib.GlideApp;
import cn.dankal.basiclib.base.recyclerview.BaseRecyclerViewAdapter;
import cn.dankal.basiclib.base.recyclerview.BaseRecyclerViewHolder;
import cn.dankal.basiclib.util.image.PicUtils;
import cn.dankal.flyaudio.R;
import cn.dankal.flyaudio.friend.pickimage.StringUtil;
import cn.dankal.flyaudio.friend.utils.takevideo.utils.LogUtils;
import cn.flyaudio.phonecontrol.mycar.util.GlideUtil;

/**
 * <pre>
 *     e-mail : junfeng.nie@duntech.com.cn
 *     time   : 20/7/2020
 *     desc   :
 *     version: cn.dankal.flyaudio.personal
 *     Copyright: Copyright（c）2018
 *     Company:
 * </pre>
 *
 * @author niejunfeng
 */
public class ImgAdapter extends BaseRecyclerViewAdapter<String> {
    @Override
    protected int getLayoutResId(int viewType) {
        return R.layout.item_img;
    }

    @Override
    protected BaseRecyclerViewHolder getViewHolder(ViewGroup parent, View rootView, int viewType) {
        return new ImgAdapter.ViewHolder(rootView);
    }

    class ViewHolder extends BaseRecyclerViewHolder<String> {

        public ViewHolder(View itemView) {
            super(itemView);
        }

        @Override
        public void onBindData(String data, int position) {
            LogUtils.e(data);
            if (StringUtil.isEmpty(data)) {
                setImageResId(R.id.item_iv_icon, R.mipmap.button_add);
                setGone(R.id.item_iv_close, true);
            } else {
                GlideApp.with(context).load(data).into((ImageView) itemView.findViewById(R.id.item_iv_icon));
                setGone(R.id.item_iv_close, false);
            }
            itemView.findViewById(R.id.item_iv_icon).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    LiveEventBus.get("addImg",int.class).post(position);
                }
            });
            itemView.findViewById(R.id.item_iv_close).setOnClickListener(
                    new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            LiveEventBus.get("deleteImg",int.class).post(position);
                        }
                    }
            );
        }
    }
}

